Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks to the NFT agents #614

Merged
merged 6 commits into from
Dec 17, 2024
Merged

Tweaks to the NFT agents #614

merged 6 commits into from
Dec 17, 2024

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Dec 16, 2024

build please

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces modifications across several files in the prediction_market_agent/agents/microchain_agent directory, focusing on restructuring NFT-related functions, updating import statements, and enhancing message handling capabilities. The changes primarily involve reorganizing imports, updating type definitions for xDai, and improving the functionality of NFT treasury game agents. The modifications aim to provide more explicit handling of NFT functions and clarify the interactions between different components of the microchain agent system.

Changes

File Change Summary
microchain_agent.py - Relocated NFT_FUNCTIONS import to nft_treasury_game.messages_functions
- Updated build_agent_functions to conditionally include NFT functions
microchain_agent_keys.py - Updated import to include xdai_type
- Changed SENDING_XDAI_CAP type from float to xDai
- Initialized SENDING_XDAI_CAP using xdai_type(0.1)
app_nft_treasury_game.py - Added import for BalanceOfNFT
- Introduced NFT_TOKEN_FACTORY constant
- Updated send_message_part with xDai value input
- Enhanced show_about_agent_part to display NFT count
deploy_nft_treasury_game.py - Added NFT_TOKEN_FACTORY constant
- Updated nft_treasury_game_base_prompt with more NFT contract details
messages_functions.py - Updated SendPaidMessageToAnotherAgent to include fee parameter
- Modified description for message sending and receiving
test_messages_functions.py - Updated import path for ReceiveMessage class

Suggested reviewers

  • gabrielfior

Possibly related PRs

  • Various improvements and fixes for microchain agent #201: This PR includes updates to microchain_agent.py, specifically the addition of the build_agent_functions import and modifications to the build_agent function, which are relevant to the changes made in the main PR regarding the organization of function calls.
  • Promote Llama 3.1 to microchain repo #345: This PR also modifies microchain_agent.py, focusing on import statements and the instantiation of a generator class, which indicates a restructuring similar to the changes in the main PR.
  • Sending messages from general agent #581: This PR introduces the SendPaidMessageToAnotherAgent class, which is directly related to the changes in the main PR that involve the handling of NFT functions and message sending functionalities.
  • NFT functions for general agent #582: This PR adds NFT-related functionalities in messages_functions.py, which aligns with the main PR's focus on the organization and inclusion of NFT functions in the agent's capabilities.
  • Make nft web app nicer #602: This PR modifies the app_nft_treasury_game.py file, focusing on message handling, which is relevant to the changes in the main PR regarding the organization of function calls and imports related to messaging.
  • More interesting prompts for NFT agents #605: This PR discusses enhancements to prompts for NFT agents, which may relate to the overall functionality and organization of the agent's capabilities as described in the main PR.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3c0ced and cc79593.

📒 Files selected for processing (3)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (4 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/contracts_nft_treasury_game.py (1 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py (3 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (1)

199-203: Consider caching the NFT balance query

The NFT balance query is made every time the component refreshes (every 5 seconds). Consider caching this value or reducing the refresh frequency to minimize blockchain calls.

-    n_nft = BalanceOfNFT()(NFT_TOKEN_FACTORY, nft_agent.wallet_address)
+    @st.cache_data(ttl=60)  # Cache for 60 seconds
+    def get_nft_balance(address: str) -> int:
+        return BalanceOfNFT()(NFT_TOKEN_FACTORY, address)
+    
+    n_nft = get_nft_balance(nft_agent.wallet_address)
prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py (2)

204-205: Clarify message fee structure

The prompt should be more explicit about the fee split between recipient and treasury to avoid confusion.

-Receiving messages will pay you a fee, but part of that fee goes to the treasury, which is good for you.
+Receiving messages will pay you a fee (X% of the message cost), with the remaining Y% going to the treasury, benefiting both parties.

Line range hint 186-207: Improve prompt structure and readability

The base prompt could be better organized by grouping related information.

Consider restructuring the prompt into clear sections:

  1. Game Overview
  2. NFT Contract Details
  3. Communication Rules & Fees
  4. Treasury Mechanics
  5. Important Limitations
 def nft_treasury_game_base_prompt(wallet_address: ChecksumAddress) -> str:
     keys = MicrochainAgentKeys()
     other_agents_keys_formatted = ", ".join(
         x.wallet_address
         for x in DEPLOYED_NFT_AGENTS
         if x.wallet_address != wallet_address
     )
-    return f"""NFT Treasury game description:
+    return f"""# NFT Treasury Game Description
+
+## Game Overview
+- You participate in the securing of the NFT key to a treasury.
+- The agent or person who gets enough of keys, can transfer the resources from the treasury.
+
+## Participant Information
+- Your wallet address is {wallet_address}
+- Other agents participating and maybe still holding keys are {other_agents_keys_formatted}
+- Address of the treasury, wallet holding the treasury's Xdai, is {TREASURY_SAFE_ADDRESS}
+
+## NFT Contract Details
+- Address of the NFT contract is {NFT_TOKEN_FACTORY}
+- There are 5 keys, with token_id 0, 1, 2, 3, 4
+- You can own multiple NFT keys
+- You can use the NFT functions to interact with the NFT keys
+
+## Communication Rules & Fees
+- Agents can communicate using messages sent to wallet addresses
+- Sending a message incurs a fee
+- Receiving messages pays you a fee, with a portion going to the treasury
+- Process unseen incoming messages first (unless already processing a message)
+
+## Important Limitations
+- Maximum sending limit: {keys.SENDING_XDAI_CAP} xDai per transaction
+- Regularly check balances of your wallet and the treasury
"""
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72197b3 and 4891cae.

📒 Files selected for processing (6)
  • prediction_market_agent/agents/microchain_agent/microchain_agent.py (1 hunks)
  • prediction_market_agent/agents/microchain_agent/microchain_agent_keys.py (2 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (3 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py (3 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/messages_functions.py (3 hunks)
  • tests/agents/microchain/test_messages_functions.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/agents/microchain/test_messages_functions.py
🔇 Additional comments (9)
prediction_market_agent/agents/microchain_agent/microchain_agent_keys.py (2)

1-1: LGTM! Import statement updated for type safety

The addition of xdai_type import aligns with the type safety improvements in the codebase.


12-12: Verify the impact of changing SENDING_XDAI_CAP initialization value

The initialization value has been changed from OMEN_TINY_BET_AMOUNT to xdai_type(0.1). While this improves type safety, we should verify this doesn't impact existing functionality.

✅ Verification successful

Change to SENDING_XDAI_CAP is safe and improves type safety

The change from OMEN_TINY_BET_AMOUNT to xdai_type(0.1) for SENDING_XDAI_CAP is safe because:

  • SENDING_XDAI_CAP is only used as an upper limit for transaction amounts in the microchain_agent_keys.py
  • The value is only referenced in documentation string in deploy_nft_treasury_game.py
  • The change to use xdai_type(0.1) directly improves type safety while maintaining similar functionality
  • OMEN_TINY_BET_AMOUNT is still used separately for RECEIVER_MINIMUM_AMOUNT where it's more contextually appropriate
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of SENDING_XDAI_CAP to understand impact
rg -l "SENDING_XDAI_CAP"

# Search for OMEN_TINY_BET_AMOUNT to understand its usage
rg "OMEN_TINY_BET_AMOUNT"

Length of output: 503


Script:

#!/bin/bash
# Let's check how SENDING_XDAI_CAP is used in the deploy_nft_treasury_game.py
rg "SENDING_XDAI_CAP" prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py -A 2

# Let's also check the actual value of OMEN_TINY_BET_AMOUNT
rg "OMEN_TINY_BET_AMOUNT\s*=\s*" -A 1 prediction_market_agent/agents/microchain_agent/tooling/markets/omen/omen.py

Length of output: 473


Script:

#!/bin/bash
# Let's try to find the correct path for omen.py file
fd omen.py

# Let's also check the actual implementation to see how SENDING_XDAI_CAP is used in the code
ast-grep --pattern 'SENDING_XDAI_CAP'

Length of output: 679

prediction_market_agent/agents/microchain_agent/nft_treasury_game/messages_functions.py (3)

42-46: LGTM! Improved clarity in SendPaidMessageToAnotherAgent description

The description now clearly indicates the minimum fee requirement for message sending.


73-73: LGTM! Enhanced message count visibility

The description now includes the count of unseen messages, improving user awareness.


48-56: Verify the fee parameter type conversion

The new fee parameter is properly handled with type conversion, but we should ensure all callers are updated to provide the fee parameter.

prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (1)

72-75: LGTM! Well-constrained value input

The value input is properly constrained with minimum and maximum values, using the system's minimum amount as default.

prediction_market_agent/agents/microchain_agent/microchain_agent.py (1)

47-48: LGTM! Verify import references.

The reorganization of imports looks good, moving MESSAGES_FUNCTIONS under nft_treasury_game makes logical sense for better code organization. However, let's verify there are no broken references due to this change.

✅ Verification successful

Import changes are properly reflected across the codebase

The verification shows that all references to the messages_functions module have been properly updated to use the new location under nft_treasury_game. The test file and app_nft_treasury_game.py are correctly importing from the new path prediction_market_agent.agents.microchain_agent.nft_treasury_game.messages_functions. No references to the old import path remain in active use.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the moved MESSAGES_FUNCTIONS import doesn't break any existing references

# Check for any direct imports of messages_functions from old location
rg -l "from prediction_market_agent.agents.microchain_agent.messages_functions import"

# Check for any references to the old module path
rg -l "microchain_agent.messages_functions"

# Check if the new module is properly referenced elsewhere
rg -l "microchain_agent.nft_treasury_game.messages_functions"

Length of output: 455


Script:

#!/bin/bash
# Let's check the content of the test file to see if it needs updating
cat tests/agents/microchain/test_messages_functions.py

# Also check the content of app_nft_treasury_game.py to verify proper import usage
cat prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py

Length of output: 15532

prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py (2)

14-14: LGTM: NFT contract information import added

The addition of NFT_TOKEN_FACTORY import enhances the agent's knowledge about NFT contract interactions.


198-200: Verify NFT token IDs existence

The prompt mentions specific token IDs (0-4) but there's no validation to ensure these IDs exist in the contract.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4891cae and c3c0ced.

📒 Files selected for processing (2)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (3 hunks)
  • tests/agents/microchain/test_messages_functions.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/agents/microchain/test_messages_functions.py
🔇 Additional comments (3)
prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (3)

19-32: LGTM! Import statements are well-organized.

The new imports are logically grouped and necessary for the added NFT functionality and message handling.


72-80: LGTM! Well-implemented value input with proper constraints.

The implementation properly handles xDai value input with:

  • Minimum value validation
  • Maximum cap for safety
  • Proper decimal formatting
  • Configuration-driven defaults

204-209: Consider improving NFT balance message clarity.

While the implementation is functionally correct, the message could be clearer:

Apply this diff to improve clarity:

-        "and does not hold any NFT keys anymore"
-        if n_nft == 0
-        else f"and <span style='font-size: 1.1em;'><strong>{n_nft} NFT key{'s' if n_nft > 1 else ''}</strong></span>"
+        "and does not hold NFT keys"
+        if n_nft == 0
+        else f"and holds <span style='font-size: 1.1em;'><strong>{n_nft} NFT key{'s' if n_nft > 1 else ''}</strong></span>"

This change aligns with the previous review suggestion while maintaining the existing styling.

@kongzii kongzii merged commit c850589 into main Dec 17, 2024
9 of 10 checks passed
@kongzii kongzii deleted the peter/nftupgrades branch December 17, 2024 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants